package cn.edu.sctu.sctu_lysd.rong;

import android.content.Context;

import cn.edu.sctu.sctu_lysd.bean.ChatToken;
import cn.edu.sctu.sctu_lysd.bean.JsonBaseBeen;
import cn.edu.sctu.sctu_lysd.cofig.CacheKeyConfig;
import cn.edu.sctu.sctu_lysd.net.NetService;
import cn.edu.sctu.sctu_lysd.net.RetrofitHelper;
import cn.edu.sctu.sctu_lysd.utils.SharePreferenceUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by wangfuxin on 2017-04-20.
 */

public class GetRongToken {

    public void getRongTokenAddConnectRY(long userId, final Context context){

        RetrofitHelper helper = RetrofitHelper.getInstance();

        NetService service = (NetService) helper.getService(NetService.class);

        service.getChatToken(userId).enqueue(new Callback<JsonBaseBeen<ChatToken>>() {
            @Override
            public void onResponse(Call<JsonBaseBeen<ChatToken>> call, Response<JsonBaseBeen<ChatToken>> response) {

                if (response.code() == 200 && response.body().getMeta().getCode() == 200)

                SharePreferenceUtils.getInstance(context).setCache(CacheKeyConfig.CACHE_CHAT_TOKEN,response.body().getData().getToken());

            }

            @Override
            public void onFailure(Call<JsonBaseBeen<ChatToken>> call, Throwable t) {

            }
        });



    }

}
